<?php
namespace app\admin\controller;
use think\Controller;
use think\File;
use think\Db;
header("content-type:text/html; charset=utf8");
class Conference extends Controller{
    public function Conference(){//酒店展示页面
       $date= Db::table("hotel")->where("type=0")->order('id desc')->paginate(5);
        $page = $date->render();
       return view("Conference/conference",["bo"=>$date,"page"=>$page]);
    }
    public function select($conference_id)
    {//模糊查询
        $get=$conference_id;
        $name = $_POST["keywords"];
        if ($name == "") {//判断name值是否为空
            $row = Db::name('Conference_release')->paginate(6);
//            $this->error('查询数据不能为空','index','',1);
        } else {                                                                                           //不否为空进行模糊查询
            $row = Db::table("Conference_release")->where("
                name like '%{$name}'
                or name like '%{$name}'
                or name like '%{$name}%'
                ")->paginate(6);  //查询 细分类的表 找到对应的类名
        }
        $page = $row->render();
        return view('Conference/conference_show',array('bo'=>$row,'page'=>$page,'conference_id'=>$get));
    }
    public function  show($conference_id){//会议展示页面
       $get=$conference_id;

       $date=Db::table("Conference_release")->where("hotel_id=".$get)->order('id desc')->paginate($listRows=6,$simple=false,$config=['query'=>array("conference_id"=>$get)]);
        $cc = array();
        for($i=0;$i<count($date);$i++){
            $cc[$i]['img'] = explode("/",$date[$i]["img"]);
        }
        $page = $date->render();
       return view("Conference/conference_show",["cc"=>$cc,"bo"=>$date,"conference_id"=>$get,"page"=>$page]);
    }
    public function  add($conference_id){//会议添加页面
        $get=$conference_id;
        $date=Db::table("hotel")->where("id=".$get)->paginate(6);
        $page = $date->render();
        return view("Conference/conference_add",["bo"=>$date,"conference_id"=>$get,"page"=>$page]);
    }
    public function  conference_release($conference_id){//会议操作页面
        $get=$conference_id;
        $date=Db::table("Conference_release")->where("id=".$get)->paginate(6);
        $cc = array();
        for($i=0;$i<count($date);$i++){
            $cc[$i]['img'] = explode("/",$date[$i]["img"]);
        }
        $page = $date->render();
        return view("Conference/conference_release",["cc"=>$cc,"bo"=>$date,"conference_id"=>$get,"page"=>$page]);
    }
    public function conference_update($conference_id){//会议修改页面
        $get=$conference_id;
        $date=Db::table("Conference_release")->where("id=".$get)->select();
        $cc="";
        for($i=0;$i<count($date);$i++){
            $cc[$i]['img'] = explode("/",$date[$i]["img"]);
        }
        return view("Conference/conference_update",["cc"=>$cc,"bo"=>$date,"conference_id"=>$get]);
    }
    public function conference_add($conference_id){//会议上传页面
        $get=$conference_id;
        $file = request()->file("file");
     if(request()->isPost()){
         // 获取表单上传文件 例如上传了001.jpg
            $cc="";
         foreach($file as $files) {
             $info = $files->move(ROOT_PATH . 'public' . DS . 'uploads');
             if ($info) {
                 $cc .= $info->getSaveName()."/" ;
                 $img = substr($cc,0,strlen($cc)-1);
             } else {
                 $this->success('添加失败');
             }
          }
                $array=[
                    "hotel_id"=>$get,
                    'name'=>$_POST["name"],
                    'img'=>$img,
                    'introduce'=>$_POST["introduce"],
                    'day'=>$_POST["day_amounts"],
                    'moring'=>$_POST["moring_amounts"],
                    'afternoon'=>$_POST["afternoon_amounts"],
                    'night'=>$_POST["night_amounts"],
                    'time'=>$_POST["time"],
                ];
                $aa=Db::table("conference_release")->insert($array);
                if($aa){
                    $date=Db::table("Conference_release")->where("id=".$get)->paginate(6);
                    $page = $date->render();
                    return redirect("show",["bo"=>$date,"conference_id"=>$get,"page"=>$page]);
                }else{
                    $this->error("添加失败");
                }
            }else{
                $this->error("上传失败");
            }
         }

//     }

    public function conference_delete($conference_id)
    {//会议删除页面
        $get = $conference_id;
        $aa = Db::table("Conference_release")->where("id=".$get)->delete();
            if ($aa) {
                $this->success("删除成功", "Conference","",1);
            } else {
                $this->error("删除失败", "conference_release");
            }
        }
    
    public function update($conference_id){//会议修改页面
        $get=$conference_id;
        $file = request()->file("img");
        $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
        $img  = $info->getSaveName();
        $array=[
            'id'=>$get,
            'name'=>$_POST["name"],
            'img'=>$img,
            'introduce'=>$_POST["introduce"],
            'day'=>$_POST["day_amounts"],
            'moring'=>$_POST["moring_amounts"],
            'afternoon'=>$_POST["afternoon_amounts"],
            'night'=>$_POST["night_amounts"],
            'time'=>$_POST["time"],
        ];
        $data=Db::table("Conference_release")->where("id=".$get)->update($array);
        if($data){
            $date=Db::table("Conference_release")->where("id=".$get)->order('id desc')->paginate(5);
            $page = $date->render();
            return redirect("conference_release",["bo"=>$date,"conference_id"=>$get,"page"=>$page]);
        }else{
            $date=Db::table("Conference_release")->where("id=".$get)->order('id desc')->paginate(5);
            $page = $date->render();
            return redirect("conference_release",["bo"=>$date,"conference_id"=>$get,"page"=>$page]);
        }
    }
    public  function conference_order(){
        $list = Db::name('meeting  ')->paginate(5);
        $page = $list->render();
        return view("order",array("data"=>$list,"page"=>$page));
    }

}